$(function() {
	//设置活动按钮
	changeHeaderMenu(2);
	changeMenu(2, 1);
	savehandle();
	$.getJSON('/fw/agent/agentReg_findByName.action', {
		'agentName':heading.userName
	},function(data){
		data = data.rows[0];
		$('#agentEmail').val(data.agentEmail);
	});
});

function successCallBack() {
}

/**
 * 提示信息处理
 */
function savehandle() {
	$('#alertdiv').hide();
	$('#alertdiv').savehandle( {
		fieldMap : {},
		successMsg : '添加成功！',
		failMsg : '添加失败！错误：',
		success : successCallBack
	});
}

function ret(){
	$('#agentPwd').val("");
	$('#nAgentPwd1').val("");
	$('#nAgentPwd2').val("");
	$('#agentEmail').val("");
}

function change() {
	var agentPwd = $('#agentPwd').val();
	if(!agentPwd){
		$('#alertdiv').savehandle('setmsg', {msg : '请输入密码!',timer : 2000});
		return;
	}
	var nAgentPwd1 = $('#nAgentPwd1').val();
	var nAgentPwd2 = $('#nAgentPwd2').val();
	if(!nAgentPwd1){
		$('#alertdiv').savehandle('setmsg', {msg : '请输入新密码!',timer : 2000});
		return;
	}
	if(!nAgentPwd2){
		$('#alertdiv').savehandle('setmsg', {msg : '请输入确认密码!',timer : 2000});
		return;
	}
	if(nAgentPwd1 != nAgentPwd2){
		$('#alertdiv').savehandle('setmsg', {msg : '请确认两次密码输入一致!',timer : 2000});
		return;
	}
	var agentEmail = $('#agentEmail').val();
	if(!agentEmail){
		$('#alertdiv').savehandle('setmsg', {msg : '请输入邮箱!',timer : 2000});
		return;
	}
	var data = {"oldPwd":agentPwd,"password":nAgentPwd2,"agentEmail":agentEmail};
	$.getJSON('/fw/agent/agentReg_changePwd.action', data, function(data) {
		if (data.success) {
			$('#alertdiv').savehandle('setmsg', {
				msg : '成功!',
				timer : 2000
			});
			setTimeout(function() {
				location.href = '/fw/j_spring_security_logout';
			}, 2000);
		} else {
			var msg = data.result;
			$('#alertdiv').savehandle('setmsg', {
				msg : msg.errors,
				timer : 2000
			});
		}
	});
}
